package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.PinYinUtils;
import com.scs.application.modules.base.entity.Mfg;
import com.scs.application.modules.base.mapper.MfgMapper;
import com.scs.application.modules.base.service.MfgService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 */
@Service
public class MfgServiceImpl extends BaseServiceImpl<MfgMapper, Mfg> implements MfgService {
    @Override
    public boolean saveOrUpdate(Mfg entity) {
        int count = super.count(Wrappers.<Mfg>query().eq("name", entity.getName()).ne(!entity.isNewRecord(), "id", entity.getId()));
        if (count > 0) {
            throw new BusinessException("厂商名字【" + entity.getName() + "】已存在，请使用其他名称");
        }
        entity.setNamePy(PinYinUtils.getAlpha(entity.getName()));
        return super.saveOrUpdate(entity);
    }
}
